package ru.alt22.visor.php.ui.utils;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;

public class LayoutUtils {
	
	public static void addWrapper(Composite composite) {
		addWrapper(composite, 1);
	}
	
	public static void addWrapper(Composite composite, int hSpan) {
		Label wrapper = new Label(composite, SWT.WRAP);
		setGridData(wrapper, SWT.FILL, SWT.CENTER, hSpan, 1, 0, 0);
	}
	
	public static void addSeparator(Composite composite, boolean horizontal, int span) {
		Label separator = new Label(composite, SWT.SEPARATOR | (horizontal ? SWT.HORIZONTAL : SWT.VERTICAL));
		if (horizontal) {
			setGridData(separator, SWT.FILL, SWT.FILL, span, 1, 0, 0);
		} else {
			setGridData(separator, SWT.FILL, SWT.FILL, 1, span, 0, 0);
		}
	}

	public static void setGridData(Control component, int hAligment, boolean grabHSpace, int vAligment, boolean grabVSpace) {
		GridData gd = new GridData();
		gd.horizontalAlignment = hAligment;
		gd.verticalAlignment = vAligment;
		gd.grabExcessHorizontalSpace = grabHSpace;
		gd.grabExcessVerticalSpace = grabVSpace;
		component.setLayoutData(gd);
	}
	
	public static void setGridData(Control component, int hAligment, int vAligment, int hSpan, int vSpan, int hIndent, int vIndent) {
		GridData gd = new GridData();
		gd.horizontalAlignment = hAligment;
		gd.verticalAlignment = vAligment;
		gd.horizontalSpan = hSpan;
		gd.verticalSpan = vSpan;
		gd.horizontalIndent = hIndent;
		gd.verticalIndent = vIndent;
		component.setLayoutData(gd);
	}
	
}
